home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers1.zip / MOVEMEM.ASM < prev    next >
Assembly Source File  |  1992-01-17  |  1KB  |  48 lines

  1. ;put into the public domain by Russell Nelson, nelson@crynwr.com
  2.  
  3. ;movemem has one of three values: movemem_test, movemem_386, movemem_86.
  4. ;it's initialized to the first, and the code that it points to changes
  5. ;it to the appropriate move routine.
  6.  
  7. movemem    dw    movemem_test
  8.  
  9. movemem_test:
  10.     pushf
  11.     pop    ax
  12.     or    ax,7000h        ;the 386 lets us set these bits
  13.     push    ax
  14.     popf
  15.     pushf
  16.     pop    ax
  17.     test    ax,7000h        ;did the bits get set?
  18.     mov    ax,offset movemem_86
  19.     je    movemem_test_1        ;no.
  20.     mov    ax,offset movemem_386    ;yes, use a 386-optimized move.
  21. movemem_test_1:
  22.     mov    cs:movemem,ax
  23.     jmp    ax
  24.  
  25. movemem_386:
  26. movemem_86:
  27. ;does the same thing as "rep movsb", only 50% faster.
  28. ;moves words instead of bytes, and handles the case of both addresses odd
  29. ;efficiently.  There is no way to handle one address odd efficiently.
  30. ;This routine always aligns the source address in the hopes that the
  31. ;destination address will also get aligned.  This is from Phil Karn's
  32. ;code from ec.c, a part of his NET package.  I bummed a few instructions
  33. ;out.
  34.     jcxz    movemem_cnte        ; If zero, we're done already.
  35.     test    si,1            ; Does source start on odd byte?
  36.     jz    movemem_adre        ; Go if not
  37.     movsb                ; Yes, move the first byte
  38.     dec    cx            ; Count that byte
  39. movemem_adre:
  40.     shr    cx,1            ; convert to word count
  41.     rep    movsw            ; Move the bulk as words
  42.     jnc    movemem_cnte        ; Go if the count was even
  43.     movsb                ; Move leftover last byte
  44. movemem_cnte:
  45.     ret
  46.  
  47.  
  48.